export default{
  namespaced: true,
  
  state:()=>({
    token: 'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VySWQiOiIzIn0.nrLl6Feqxpml7BS7yPNbLHAT7TD4FgnQPWPlUYIzdEQ',
    avatar: '',
    userinfo: JSON.parse(uni.getStorageSync('userinfo') || '{}')
  }),
  
  mutations: {
    updateUserInfo(state,userinfo){
      state.userinfo = userinfo
      this.commit('User/saveUserInfoToStorage')
    },
    
    saveUserInfoToStorage(state){
      uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
    },
    
    updateToken(state,token){
      state.token = token
      this.commit('User/saveTokenToStorage')
    },
    
    saveTokenToStorage(state){
      uni.setStorageSync('token',state.token)
    }
  },
  
  getters: {},
}